// ModelView.ts
import { Component } from 'cc';
import { DataBinder, BindingInfo } from './DataBinder';

export abstract class ModelView<T extends object> extends Component {
  protected model!: T;

  /**
   * 绑定 Model 与 View
   * @param initialModel  初始数据对象（会被 Proxy 包裹）
   * @param bindings      字段到视图组件的绑定信息
   */
  protected bindModel(
    initialModel: T,
    bindings: Partial<Record<keyof T, BindingInfo>>
  ) {
    const binder = new DataBinder(initialModel, bindings);
    this.model = binder.getModel();
  }
}
